//
//  WXUserAccountModel.swift
//  weibo
//
//  Created by 王旭 on 16/4/19.
//  Copyright © 2016年 王旭. All rights reserved.
//

import UIKit


class WXUserAccountModel: NSObject, NSCoding {
    
    //    "access_token" = "2.00BLRc_G9WV6dBe14d4fc155tW2q2D";
    //    "expires_in" = 157679999;
    //    "remind_in" = 157679999;
    //    uid = 5786669871;
    //    "name": Xphh2015;
    //    "avatar_large": http://tp4.sinaimg.cn/5786669871/180/0/1;
    
    var access_token : String?
    var expires_in :NSTimeInterval = 0 {
        didSet{
            expiresDate = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
    var remind_in :String?
    var uid :String?
    var name :String?
    var avatar_large :String?
    var expiresDate :NSDate?
    
    init(dic:[String : AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dic)
    }
    
    //反归档
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        expires_in = aDecoder.decodeDoubleForKey("expires_in")
        remind_in = aDecoder.decodeObjectForKey("remind_in") as? String
        name = aDecoder.decodeObjectForKey("name") as? String
        avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
        uid = aDecoder.decodeObjectForKey("uid") as? String
        expiresDate = aDecoder.decodeObjectForKey("expiresDate") as? NSDate
    }
    //归档
    func encodeWithCoder(encoder: NSCoder) {
        encoder.encodeObject(access_token, forKey: "access_token")
        encoder.encodeDouble(expires_in, forKey: "expires_in")
        encoder.encodeObject(uid, forKey: "uid")
        encoder.encodeObject(remind_in, forKey: "remind_in")
        encoder.encodeObject(name, forKey: "name")
        encoder.encodeObject(avatar_large, forKey: "avatar_large")
        encoder.encodeObject(expiresDate, forKey: "expiresDate")
    }
    
}
